#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/wait.h>
#include <sys/types.h>

int main()
{
    pid_t id = fork();
    if(id == 0)
    {
        int cnt = 5;
        while(cnt)
        {
            printf("child is running,pid:%d,ppid:%d\n",getpid(),getppid());
            sleep(1);
            cnt--;
        }
        printf("子进程退出，马上变僵尸\n");
        exit(0);
    }
    
    printf("父进程休眠\n");
    sleep(10);
    printf("父进程开始回收了\n");
    pid_t rid = wait(NULL);
    if(rid > 0)
    {
        printf("wait cuccess,rid:%d\n",rid);
    }
    printf("父进程回收僵尸成功\n");
    sleep(3);

    return 0;
}




/*
void print()
{
    printf("hello print\n");
    exit(4);
}


int main()
{
    while(1)
    {
        printf("I am a process:%d\n",getpid());
        sleep(1);
        print();
        //exit(3);
    }
    return 0;
}
*/

/*
int main()
{
    printf("hello world\n");
    return 0;
}

*/ 
